# Copyright 2023 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//lib:selects.bzl", "selects")
load("//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test")

package(default_visibility = ["//visibility:public"])

yacl_cc_library(
    name = "spi",
    srcs = ["pairing_spi.cc"],
    hdrs = ["pairing_spi.h"],
    deps = [
        "//yacl/crypto/pairing:pairing_interface",
    ],
)

yacl_cc_library(
    name = "mcl_pairing_header",
    hdrs = ["mcl_pairing_header.h"],
    copts = [
    ],
    defines = selects.with_or({
        ("@yacl//bazel:yacl_build_as_debug", "@yacl//bazel:yacl_build_as_fast"): [
            # Macro `MCL_ALL_PAIRING_FOR_YACL` enables libmcl's all pairing curves
            # and not that they are not standard pairing instances.
            # !Only for test and don't use this in production!
            "MCL_ALL_PAIRING_FOR_YACL",
        ],
        "//conditions:default": [],
    }),
    deps = ["@com_github_herumi_mcl//:mcl"],
)

yacl_cc_library(
    name = "mcl_factory",
    srcs = [
        "mcl_bls12_381.cc",
        "mcl_bls12_381.h",
        "mcl_factory.cc",
        "mcl_pairing_group.cc",
    ],
    hdrs = [
        "mcl_pairing_group.h",
    ],
    deps = [
        ":mcl_pairing_header",
        ":spi",
        "//yacl/crypto/ecc",
        "//yacl/math/galois_field/factory:mcl_factory",
    ],
    alwayslink = 1,
)

yacl_cc_test(
    name = "mcl_factory_test",
    srcs = ["mcl_factory_test.cc"],
    deps = [
        ":mcl_factory",
        "//yacl/crypto/rand",
    ],
)
